#ifndef AVALON_BINARYSERIALIZER_HPP
#define AVALON_BINARYSERIALIZER_HPP
#include "Avalon/IO/Buffer.hpp"
#include "Avalon/Serialization/Serializer.hpp"

namespace Avalon {
namespace Serialization {

  /*! \class BinarySerializer
   *  \brief Implements the Serializer using binary serialization.
   *  \author Kamal Mansouri <kranar@hotmail.com>
   */
  class BinarySerializer : public Serializer {
    public:

      //! Constructs a BinarySerializer.
      BinarySerializer();

      virtual ~BinarySerializer();

      virtual IO::Buffer GetSerializedData();

      virtual void Shuttle(const char* name, bool& value);

      virtual void Shuttle(const char* name, char& value);

      virtual void Shuttle(const char* name, short& value);

      virtual void Shuttle(const char* name, int& value);

      virtual void Shuttle(const char* name, long& value);

      virtual void Shuttle(const char* name, long long& value);

      virtual void Shuttle(const char* name, float& value);

      virtual void Shuttle(const char* name, double& value);

      virtual void Shuttle(const char* name, std::string& value);

      virtual void Shuttle(const char* name, IO::Buffer& data);

      using Serializer::Shuttle;

    private:
      IO::Buffer m_buffer;
      char* m_writeIterator;

      template<typename T> void SerializePrimitive(T value);
      void ResizeIfNeeded(int additionalSizeRequired);
  };
}
}

#endif // AVALON_BINARYSERIALIZER_HPP
